package com.yoo.ons.dialog

import android.app.Activity
import android.view.animation.AnimationUtils
import android.widget.ImageView
import android.widget.TextView
import androidx.fragment.app.FragmentActivity
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.gyf.immersionbar.ImmersionBar
import com.yoo.module_base.utils.setOnClickCallback
import com.yoo.module_base.utils.setSystemBottomNavBarColor
import com.yoo.module_base.utils.setSystemBottomNavBarNoColor
import com.yoo.ons.R
import com.yoo.ons.adapter.UpdateUserInfoAdapter
import com.yoo.ons.model.UserWantOrYouAcceptModel
import razerdp.basepopup.BasePopupWindow

class UpdateGenderAndWantPopup(activity: FragmentActivity, var title :String, var list:ArrayList<UserWantOrYouAcceptModel>, var callBack:(value:UserWantOrYouAcceptModel)->Unit):BasePopupWindow(activity) {
    init {
        setContentView(R.layout.popup_update_gender_want)
        initView(activity)
        showAnimation=  AnimationUtils.loadAnimation(activity, com.yoo.module_res.R.anim.anims_slide_in_bottom)
        dismissAnimation=  AnimationUtils.loadAnimation(activity, com.yoo.module_res.R.anim.anims_slide_out_bottom)
    }

    fun initView(activity:FragmentActivity){
        val popupClose = findViewById<ImageView>(R.id.popup_close)
        val popupTitle = findViewById<TextView>(R.id.popup_title)
        val popupSelectList = findViewById<RecyclerView>(R.id.popup_select_list)
        val popupCustomSave = findViewById<TextView>(R.id.popup_custom_save)
        popupClose.setOnClickCallback {
            dismiss()
        }
        popupTitle.text=title
        //设置列表
        popupSelectList.layoutManager=LinearLayoutManager(activity)
        val updateUserInfoAdapter = UpdateUserInfoAdapter(activity) {
            for (i in 0 until  list.size){
                list[i].selected=0
            }
            list[it].selected=1
            popupSelectList.adapter?.notifyDataSetChanged()
        }
        updateUserInfoAdapter.addAll(list)
        popupSelectList.adapter=updateUserInfoAdapter




        popupCustomSave.setOnClickCallback {
            val acceptModels = list.filter {
                it.selected == 1
            }
            if (acceptModels.isNotEmpty()){
                callBack.invoke(acceptModels[0])
            }
            dismiss()
        }



        //设置底部导航栏颜色
        setSystemBottomNavBarColor(activity)
        onDismissListener =object : OnDismissListener() {
            override fun onDismiss() {
                setSystemBottomNavBarNoColor(activity)
            }

        }
    }
}